<template>
  <div>
    <div>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="up"
          label="涨">
        </el-table-column>
        <el-table-column
          prop="down"
          label="跌">
        </el-table-column>
        <el-table-column
          prop="equal"
          label="平">
        </el-table-column>
        <el-table-column
          prop="corn"
          label="玉米">
        </el-table-column>
        <el-table-column
          prop="soyabean"
          label="豆子">
        </el-table-column>
        <el-table-column
          prop="peanut"
          label="花生">
        </el-table-column>
        <el-table-column
          prop="wheat"
          label="小麦">
        </el-table-column>
        <el-table-column
          prop="silk"
          label="丝绸">
        </el-table-column>
        <el-table-column
          prop="silver"
          label="白银">
        </el-table-column>
        <el-table-column
          prop="gold"
          label="黄金">
        </el-table-column>
        <el-table-column
          prop="diamond"
          label="钻石">
        </el-table-column>
        <el-table-column
          prop="nubmer"
          label="人数">
        </el-table-column>
        <el-table-column
          prop="serviceCharge"
          label="手续">
        </el-table-column>
        <el-table-column
          prop="recycle"
          label="回收率">
        </el-table-column>
        <el-table-column
          prop="recycleTimer"
          label="每场回收">
        </el-table-column>
      </el-table>
    </div>
    <el-divider content-position="center">下注情况</el-divider>
    <div>
      <el-table :data="itemDate" border stripe style="width: 100%;">
        <el-table-column prop="sex" label="奖品" width="180" align="center">
          <template slot-scope="scope">
            <el-select v-model="award" filterable placeholder="开奖类型">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left;font-size: 16px">{{ item.label }}</span>
                <span style="float: right; color: #28a600; font-size: 8px">流行X{{ item.small }} 风靡X{{ item.big }}</span>
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="ser" label="倍数" width="210" align="center">
          <template slot-scope="scope">
            <div style="margin-top: 3px">
              <el-radio-group v-model="rateDate" size="small">
                <el-radio label="1" border>流行</el-radio>
                <el-radio label="2" border>风靡</el-radio>
              </el-radio-group>
            </div>
            <span></span>
          </template>
        </el-table-column>
        <el-table-column prop="see" label="操作" width="210" align="center">
          <template slot-scope="scope">
            <div style="margin-top: 3px">
              <el-button type="success" plain @click="onSubmit">提交</el-button>
            </div>
            <span></span>
          </template>
        </el-table-column>
      </el-table>
      <el-divider content-position="center">大盘</el-divider>
      <el-table :data="itemDate" border stripe style="width: 100%;">
        <el-table-column prop="se" label="涨跌" width="390" align="center">
          <template slot-scope="scope">
            <div style="margin-top: 3px">
              <el-radio-group v-model="upOrDown" size="medium">
                <el-radio label="1" border>涨</el-radio>
                <el-radio label="2" border>跌</el-radio>
                <el-radio label="3" border>平</el-radio>
              </el-radio-group>
            </div>
            <span></span>
          </template>
        </el-table-column>
        <el-table-column prop="seq" label="操作" width="210" align="center">
          <template slot-scope="scope">
            <div style="margin-top: 3px">
              <el-button type="success" plain @click="onSubmitOne">提交</el-button>
            </div>
            <span></span>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin: 20px 0;"></div>
      <div style="max-width: 500px">
        <el-input style="width: 55%" v-model.number="recovery" type="number" placeholder="请输入内容"></el-input>
        <el-button type="primary" icon="el-icon-setting" @click="recycleClick">设 置 回 收 率</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  var map = new Map();
  import axios from 'axios'

  export default {
    created() {
      axios.get("/dsfscene").then(resp => {
        if (resp.data.result) {
          this.tableData = [resp.data.msg]
        }
      });
      axios.get("/dsfpos").then(resp => {
        if (resp.data.result) {
          this.options = resp.data.msg
          for (let i = 0; i < this.options.length; i++) {
            let v = this.options[i];
            map.set(v.value, v);
          }
        }
      });
    },
    data() {
      return {
        tableData: [],
        options: [],
        itemDate: [{
          value: '4',
          label: '玉米',
          big: '5',
          small: '3'
        }],
        rateDate: '1',
        award: '',
        recovery:0,
        upOrDown: '1'
      }
    },
    methods: {
      onSubmit() {
        if (this.award === '') {
          this.$message({
            type: 'error',
            message: '请选择要开的奖品!'
          });
          return;
        }
        let m = map.get(this.award);
        let t = this.rateDate == 1 ? m.small : m.big;
        let s = this.rateDate == 1 ? "流行" : "风靡";
        let str = "大三风将开出<" + m.label + "> " + s + " 倍数x" + t;
        this.$confirm(str, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          console.log(this.award);
          axios.post("/showone", {
            rateDate: this.rateDate,
            award: this.award,
          }).then(resp => {
            let msg = resp.data.result ? resp.data.msg : resp.data.error;
            this.$message({
              type: 'success',
              message: msg
            });
          }).catch(err => {
            this.$message({
              type: 'info',
              message: '控制失败!'
            });
          })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      onSubmitOne() {
        let n = '涨';
        if (this.upOrDown === 1) {
          n = '涨';
        } else if (this.upOrDown === 2) {
          n = '跌';
        } else if (this.upOrDown === 3) {
          n = '平';
        }
        let str = "大三风将开出<" + n + "> ";
        this.$confirm(str, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.get("/showaward", {
            params: {
              upOrDown: this.upOrDown
            }
          }).then(resp => {
            let msg = resp.data.result ? resp.data.msg : resp.data.error;
            this.$message({
              type: 'success',
              message: msg
            });
          }).catch(err => {
            this.$message({
              type: 'info',
              message: '控制失败!'
            });
          })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      recycleClick(){
        if(this.recovery === ""){
          this.$notify.error({
            title: '错误',
            message: '请输入调整率'
          });
          return
        }
        axios.get("dsfsetrecovery",{
          params: {
            recovery : this.recovery
          }
        }).then(resp => {
          this.$notify({
            title: '成功',
            message: resp.data.msg,
            type: 'success'
          });
        }).catch(err => {
          this.$notify({
            title: '警告',
            message: err.data.error,
            type: 'warning'
          });
        })
      },
    }
  }
</script>

<style scoped>

</style>
